package com.jeestudio.common.beans;

import com.jeestudio.common.enums.MsgBox;
import lombok.Data;

/**
 * Created by shuttle on 18/8/9.
 */
@Data
public class ResponseResult<T> {
    private int code;
    private String msg;
    private T data;
    private Object ext;

    public ResponseResult(){

    }

    public ResponseResult(T t){
        this.code = MsgBox.SUCCESS.getCode();
        this.msg = MsgBox.SUCCESS.getMsg();
        this.data = t;
    }

    public static ResponseResult buildErrorResult(String msg){
        return buildResult(msg,0);
    }

    public static ResponseResult buildResult(String msg, int code){
        ResponseResult result = new ResponseResult();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static ResponseResult buildResult(MsgBox box){
        return buildResult(box, null);
    }

    public static ResponseResult buildResult(MsgBox box, Object data){
        ResponseResult result = new ResponseResult();
        result.setCode(box.getCode());
        result.setMsg(box.getMsg());
        if(null != data) {
            result.setData(data);
        }
        return result;
    }

    public ResponseResult(int code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public ResponseResult(int code, String msg, T t){
        this.code = code;
        this.msg = msg;
        this.data = t;
    }

    public ResponseResult(int code, String msg, T t, Object ext){
        this.code = code;
        this.msg = msg;
        this.data = t;
        this.ext = ext;
    }
}
